/*
 * ErrorHandler.java
 *
 * Created on September 10, 2006, 4:20 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package smfbackup;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import javax.swing.JOptionPane;
import org.apache.log4j.Logger;

/**
 *
 * @author Iulian
 */
public class ErrorHandler {
    
    private static Logger log = Logger.getLogger(ErrorHandler.class);
    
    /** Creates a new instance of ErrorHandler */
    private ErrorHandler() {
    }
    
    public static void showError(String title, Throwable t) {

        // also log the exception
        log.error(title, t);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        t.printStackTrace(new PrintStream(baos));
        
        byte meaningfull[] = new byte[520];
        byte data[] = baos.toByteArray();
        
        int i;
        for (i = 0; i < 512; i++) {
            if (i >= data.length)
                break;
            meaningfull[i] = data[i];
        }
        
        meaningfull[i] = '\n';
        meaningfull[i+1]='.';
        meaningfull[i+2]='.';
        meaningfull[i+3]='.';
        meaningfull[i+4]='.';
        
        JOptionPane.showMessageDialog(null, new String(meaningfull, 0, i+4), title, JOptionPane.ERROR_MESSAGE);
    }
}
